package collection;

import java.util.Date;

/**
 * Title：
 * Description：
 * Created by Myth on 4/19/2017.
 */
public class Item implements Comparable<Item>{

    private String name;
    private int money;
    private Date date;

    public Item(String name, int money, Date date) {
        this.name = name;
        this.money = money;
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "Name: " + name + " Money: " + money + " Date: " + date;
    }

    //两个对象的equal 为0 那么 hashCode 必须一致
    @Override
    public int hashCode() {
        return  name.hashCode()+ date.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Item) {
            Item item = (Item) obj;
            if (item.name.equals(name) && item.money==money && item.date==date) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int compareTo(Item o) {
        if (o.money > money)
            return 1;
        if (o.money < money)
            return -1;
        return 0;
    }
}
